package org.taobao.ibatiside.codegen;

import org.taobao.ibatiside.core.genmodel.DAOGenModel;
import org.apache.commons.lang.StringUtils;

public class DaoImplGen
{
  protected static String nl;
  public static synchronized DaoImplGen create(String lineSeparator)
  {
    nl = lineSeparator;
    DaoImplGen result = new DaoImplGen();
    nl = null;
    return result;
  }

  public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
  protected final String TEXT_1 = "";
  protected final String TEXT_2 = NL + "package ";
  protected final String TEXT_3 = ";" + NL;
  protected final String TEXT_4 = NL + "import ";
  protected final String TEXT_5 = ".";
  protected final String TEXT_6 = ";";
  protected final String TEXT_7 = NL + NL + "public class ";
  protected final String TEXT_8 = " ";
  protected final String TEXT_9 = " implements ";
  protected final String TEXT_10 = " ";
  protected final String TEXT_11 = "{" + NL + "" + NL + "}";

  public String generate(Object argument)
  {
    final StringBuffer stringBuffer = new StringBuffer();
    stringBuffer.append(TEXT_1);
    
DAOGenModel model = (DAOGenModel)argument;

    stringBuffer.append(TEXT_2);
    stringBuffer.append(model.getImplPkg());
    stringBuffer.append(TEXT_3);
    if(model.isEnableInterface() && StringUtils.isNotBlank(model.getInterfacePkg())){
    stringBuffer.append(TEXT_4);
    stringBuffer.append(model.getInterfacePkg());
    stringBuffer.append(TEXT_5);
    stringBuffer.append(model.getInterfaceName());
    stringBuffer.append(TEXT_6);
    }
    stringBuffer.append(TEXT_7);
    stringBuffer.append(model.getImplName());
    stringBuffer.append(TEXT_8);
    if(model.isEnableInterface()){
    stringBuffer.append(TEXT_9);
    stringBuffer.append(model.getInterfaceName());
    stringBuffer.append(TEXT_10);
    }
    stringBuffer.append(TEXT_11);
    return stringBuffer.toString();
  }
}
